<?php
namespace Sys\Controller;
use Todo\Controller\ApiController;

class ConfigController extends ApiController {
    /**
     * 自定义查询条件
     * @param array &$where 丢生成的查询条件
     */
    protected function _filter(&$where){
        $keywords = I('request.keywords');
        if($keywords){
            $where['title'] = array('like', '%'.$keywords.'%');
        }
    }

    /**
     * 根据配置中的起始年级，计算系统中使用的年级
     */
    public function grade(){
        $this->_loadModel();
        $end = intval(date('Y'));
        $gradeInfo = $this->_model->findByField('code', 'GRADE_START');
        $start = intval($gradeInfo['value']);
        if($start == 0) $start = $end;
        $list = array();
        while ($start <= $end) {
            $list[]=array(
                'id'=>$start,
                'title'=>$start
            );
            $start++;
        }
        $this->apiData($list);
    }

    /**
     * 配置中的学制
     */
    public function xz(){
        $this->_loadModel();
        $xzInfo = $this->_model->findByField('code', 'SCHOOL_XZ');
        $xzArr = explode(',', $xzInfo['value']);
        $list = array();
        foreach ($xzArr as $xz) {
            $list[]=array(
                'id'=>$xz,
                'title'=>$xz
            );
        }
        $this->apiData($list);
    }
}